<template>
	<view>
		<cu-custom bgColor="bg-red" :isBack="true">		<block slot="backText"></block>
			<block slot="content">区域团队</block>
		</cu-custom>

		<scroll-view scroll-x class="bg-white nav text-center">
			<view class="cu-item" v-for="(item,index) in detail" :key="index" :class="index==TabCur?'cur text-'+theme:'text-gray'"
			 @tap="tabSelect" :data-id="index">
				{{item.name}}({{item.achievement}})
			</view>
		</scroll-view>

		<view class="bg-white margin radius overflow list">
			<block v-for="(item,index) in list" :key="index">
				<view class="space-between solid-bottom padding-sm">
					<view class="cu-avatar lg round default-bg">
						<image :src="item.member.head_portrait" mode="aspectFill"></image>
					</view>
					<view class="w100 margin-lr-sm">
						<view class="text-lg">{{item.member.realname | hiddenN(1,1)}}</view>
						<view class="margin-top-xs">{{item.remark}}</view>
					</view>
					<view class="action text-right">
						<view>{{$common.timeFormat(item.created_at,'YYYY-MM-DD')}}</view>
						<view class="margin-top-xs text-price text-red">{{item.achievement}}</view>
					</view>
				</view>
			</block>
			<view class="cu-load margin-center" :class="loading?'loading':'over'"></view>
		</view>
	</view>
</template>

<script>
	export default {
		filters: {
			hiddenN: function(str, frontLen, endLen) {
				if (!str) return ''
				var len = str.length - frontLen - endLen;
				if (len <= 0) len = 1
				var xing = '';
				for (var i = 0; i < len; i++) {
					xing += '*';
				}
				return str.substring(0, frontLen) + xing + (str.length - frontLen > endLen ? str.substring(str.length - endLen) :
					'');
			},
		},
		data() {
			return {
				theme: this.$config.THEME(),
				detail: null,
				TabCur: 0,
				list: [],
				page: 1,
				hasMore: true,
				loading: false,
				time_type: null,
			}
		},
		onLoad(options) {
			if (options.time_type) this.time_type = options.time_type
			this.getInfo()
		},
		onReady() {},
		methods: {
			tabSelect(e) {
				if (this.TabCur != e.currentTarget.dataset.id) {
					this.TabCur = e.currentTarget.dataset.id
					this.list = []
					this.page = 1
					this.hasMore = true
					this.loading = false
					this.getList()
				}
			},
			getInfo() {
				uni.showLoading({
					title: "正在加载数据..."
				})
				var param = {}
				if (this.time_type) param.time_type = this.time_type
				this.$http
					.get('channel_region_achievement', param)
					.then((response) => {
						this.detail = response.data.data
						uni.hideLoading()
						console.log(response)
						this.getList()
					})
					.catch((response) => {
						uni.hideLoading()
						console.log(response)
					})
			},
			getList() {
				if (this.hasMore && !this.loading) {
					this.loading = true
					var t = this.detail[this.TabCur].type
					var param = {
						page: this.page,
						type: t
					}
					if (this.time_type) param.time_type = this.time_type
					this.$http
						.get('channel_region_achievement_list', param)
						.then((response) => {
							let list = this.list
							if (response.data.data.length > 0) {
								if (list.length > 0)
									list = list.concat(response.data.data)
								else list = response.data.data
								this.list = list
							} else {
								this.hasMore = false
							}
							this.page += 1
							this.loading = false
						})
						.catch((response) => {
							console.log(response)
							this.loading = false
						})

				}
			}
		},
		onReachBottom() {
			this.getList()
		}
	}
</script>

<style>
	.list .action {
		min-width: 100px;
	}
</style>
